#! /bin/sh

# Copyright (c) 2006-2012 Google, Inc. and contributors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

set -eu

if test $# = 0; then
  echo trigger filetype:.evlan
  exit 0
fi

INPUT=$1

echo findProvider special:ekam-interceptor
read INTERCEPTOR

if test "$INTERCEPTOR" = ""; then
  echo "error:  couldn't find intercept.so." >&2
  exit 1
fi

echo findProvider file:evlan/public/evlanc
read EVLANC

if test "$EVLANC" = ""; then
  echo "error:  couldn't find evlanc." >&2
  exit 1
fi

LD_PRELOAD=$INTERCEPTOR DYLD_FORCE_FLAT_NAMESPACE= DYLD_INSERT_LIBRARIES=$INTERCEPTOR \
$EVLANC "$INPUT" 3>&1 4<&0 >&2
